package cn.frh.system.controller;

import cn.frh.basic.util.AjaxResult;
import cn.frh.basic.util.pageList;
import cn.frh.system.domain.Systemdictionarytype;
import cn.frh.system.query.SystemdictionarytypeQuery;
import cn.frh.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 类型控制层接口
 * @date: 2022年08月19日 ： 9:38
 * @version: ver1.0
 * @email 1739441354@qq.com
 */
@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {
    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    @GetMapping
    public List<Systemdictionarytype> findall(){
        return systemdictionarytypeService.loadAll();
    }
    @GetMapping("/{id}")
    public Systemdictionarytype findById(@PathVariable("id") Long id){
        return systemdictionarytypeService.loadById(id);
    }


    @DeleteMapping("/{id}")
    private AjaxResult remove(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){

        try {
            if(systemdictionarytype.getId()==null){
                systemdictionarytypeService.save(systemdictionarytype);

            }else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PatchMapping
    private AjaxResult patchRemove(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PostMapping
    public pageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){
       return systemdictionarytypeService.queryPage(systemdictionarytypeQuery);
    }
}
